<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once IMMOPHP_ROOT_PATH .'models/agence.php';

class agence extends Controller
{
    public function index()
    {
        $GLOBALS['smarty']->caching = 1;

        if( !$GLOBALS['smarty']->isCached('agence.tpl') ):
                $GLOBALS['smarty']->assign('agences', AgenceModel::getAll());
        endif;

        $t = $GLOBALS['smarty']->fetch('agence.tpl');

        $GLOBALS['smarty']->caching = 0;
        
        $GLOBALS['smarty']->assign('titre_site', $GLOBALS['setting']['titre_site']. ' - '. $GLOBALS['lang']['Agence'] );

        return $t;
    }

    public function getCarte()
    {
        global $map;

        $agence_id = $_GET['agence_id'];

        $agence = AgenceModel::getById($agence_id);

        $map->addMarkerByAddress($agence['adresse'] .' '. $agence['codepostal'] . ' ' . $agence['ville'], $agence['nom'],'<div class="googlemap_html"><b>'. $agence['nom'] .'</b><br />' . $agence['adresse'] .' <br /> '. $agence['codepostal'] . ' ' . $agence['ville'] .'</div>');
        $map->width = '400px';
        $map->height = '400px';
        $header_googlemap = $map->getHeaderJS();
        $header_googlemap .= $map->getMapJS();
        $header_googlemap .= '<style type="text/css">v\:* {behavior:url(#default#VML);}</style>';

        $GLOBALS['smarty']->assign('googlemap_code', $header_googlemap);
        $GLOBALS['smarty']->assign('carte_agence', $map->getMap() );
        $GLOBALS['smarty']->assign('titre_site', $GLOBALS['setting']['titre_site']. ' - '. $GLOBALS['lang']['Agence'] .' - ' . $agence['nom']);
        return $GLOBALS['smarty']->fetch('agence_carte.tpl');
    }
}

?>
